options compress=YES;
libname manasi ''; 
libname f831 ''; 

* CREATE VARIABLES FOR KID'S DI AND SSI APPLICATIONS;

%macro dissi(year);
	* Create variables for each observation;
	data f831.kid831summ_&year.;
		set f831.f831_cy&year._kids;

		* Applied for DI (own or self, almost all are own) in year X;
		if RID='2' then n_kid831_di_&year.=1;
			else n_kid831_di_&year.=0;

		* Applied for SSI (own or self, almost all are own) in year X;
		if RID='R' then n_kid831_ssi_&year.=1;
			else n_kid831_ssi_&year.=0;

	run;

	* Collapse on SSN so that there is only one observation per kid;
	proc means noprint data=f831.kid831summ_&year.;
		by ssn;
		var n_kid831_:;
		output out=f831.kid831summ_&year.
			max(n_kid831_di_&year. n_kid831_ssi_&year. ) = 
				n_kid831_di_&year. n_kid831_ssi_&year.;
	run;
%mend dissi;

%dissi(1985);
%dissi(1986);
%dissi(1987);
%dissi(1988);
%dissi(1989);
%dissi(1990);
%dissi(1991);
%dissi(1992);
%dissi(1993);
%dissi(1994);
%dissi(1995);
%dissi(1996);
%dissi(1997);
%dissi(1998);
%dissi(1999);
%dissi(2000);
%dissi(2001);
%dissi(2002);
%dissi(2003);
%dissi(2004);
%dissi(2005);
%dissi(2006);
%dissi(2007);
%dissi(2008);
%dissi(2009);
%dissi(2010);
%dissi(2011);

* MERGE ALL KID 831 FILES SO THEY ARE IN ONE FILE;
data f831.kid831summ_allyrs;
	merge 	
			f831.kid831summ_1985 
			f831.kid831summ_1986
			f831.kid831summ_1987 
			f831.kid831summ_1988 
			f831.kid831summ_1989
			f831.kid831summ_1990
			f831.kid831summ_1991
			f831.kid831summ_1992
			f831.kid831summ_1993
			f831.kid831summ_1994
			f831.kid831summ_1995
			f831.kid831summ_1996
			f831.kid831summ_1997
			f831.kid831summ_1998
			f831.kid831summ_1999
			f831.kid831summ_2000 
			f831.kid831summ_2001
			f831.kid831summ_2002 
			f831.kid831summ_2003 
			f831.kid831summ_2004 
			f831.kid831summ_2005 
			f831.kid831summ_2006 
			f831.kid831summ_2007 
			f831.kid831summ_2008 
			f831.kid831summ_2009 
			f831.kid831summ_2010
			f831.kid831summ_2011 
			;
	by ssn; 
run;
